home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0562.ZIP / NARC.DOC < prev    next >
Text File  |  1987-06-15  |  41KB  |  1,194 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.             Documentation for NARC.EXE
  12.  
  13.  
  14.               Written by Gary Conway
  15.  
  16.  
  17.              Infinity Design Concepts
  18.  
  19.  
  20.                Louisville, Kentucky
  21.  
  22.  
  23.                 Copyright (c) 1987
  24.  
  25.  
  26.                    Version 1.1
  27.  
  28.  
  29.  
  30.  
  31.     NARC.EXE is placed in the public domain under the user supported
  32.     shareware concept. NARC.EXE is and will remain the property of
  33.     Gary Conway. This program may not be used in any connection with
  34.     commercial ventures, nor as a sales aid, without the expressed written
  35.     consent of the author. If you find yourself using this program often
  36.     please make a contribution of $20.00 to the below address.
  37.  
  38.  
  39.             Infinity Design Concepts
  40.             1052 Parkway Drive
  41.             Louisville, Kentucky 40217
  42.  
  43.         Member  IEEE
  44.             KIPCUG
  45.             PCCL
  46.             KKUG
  47.             NSPE
  48.  
  49.  
  50.     All new releases of NARC.EXE and all other IDC utilities
  51.     can be located -FIRST- on ;
  52.  
  53.         The SoftStone   RCPM FOG #24  (supporting CP/M and MSDOS)
  54.         (502)241-4109
  55.         30 MEG
  56.         300/1200 baud
  57.         24 hrs.
  58.         Louisville, Kentucky
  59.  
  60.         Curt Edwards - SYSOP
  61.  
  62.     Sponsored by:    Kentucky Kaypro Users Group
  63.             Accounting Computer Systems
  64.             First Osborne Group
  65.  
  66.  
  67.  
  68.  .............................................................................
  69.  ........................                         ............................
  70.  ........................    TABLE OF CONTENTS    ............................
  71.  .............................................................................
  72.  
  73.                                                              Page
  74.  
  75.         WHAT IS IT ANYWAY .............................   1
  76.  
  77.         COMPATIBILITY AND AUTHOR'S RAMBLINGS ..........   2
  78.  
  79.         STOWAGE VERSIONS SUPPORTED ....................   2
  80.  
  81.         OVERVIEW ......................................   3
  82.  
  83.         COMMANDS ......................................   4-6
  84.  
  85.         SHORTCUTS .....................................   7
  86.  
  87.         ERROR MESSAGES ................................   8
  88.  
  89.         ARCHIVE FILE FORMATS AND GENERAL INFORMATION ..   9
  90.  
  91.         PACKING .......................................   9
  92.  
  93.         SQUEEZING (Huffman Coding) ....................   10-14
  94.  
  95.         CRUNCHING (Lempel-Ziv-Welch) ..................   14-15
  96.  
  97.         STOWAGE VERSIONS ..............................   16
  98.  
  99.         ARCHIVE HEADER FORMAT .........................   17
  100.  
  101.         HASHING AND CRC ...............................   18
  102.  
  103.         ARC.EXE RELEASE DATES AND VERSIONS ............   19
  104.  
  105.         NARC.EXE REVISION HISTORY .....................   19
  106.  
  107.     ........................................................................
  108.           Narc (c) 1987 Infinity Design Concepts   all rights reserved
  109.     ........................................................................
  110.  
  111.  
  112.                                ═══════════════════
  113.                        WHAT IS IT ANYWAY ?
  114.                                ═══════════════════
  115.  
  116.  
  117.  
  118.         NARC is a menu driven de-ARChive facility, written entirely in
  119.     assembler. NARC allows you to easily move from ARC file to ARC file,
  120.     with the option of viewing or printing or extracting the subfiles from
  121.     the ARChive. The program may be operated from the mouse or the
  122.     keyboard. Menus    are of the musical popup variety to add a little
  123.     "TechNoFlash" to the proceedings.
  124.  
  125. Why....
  126.  
  127.  
  128.         Because I use a lot of ARC  files and  ARC.EXE and the clones
  129.     are  reminiscent  of  the  early  Ward  Christensen CP/M days in user
  130.     interface etiquette, I wanted something a little more flexible and
  131.     friendly to use. I would like to pause here for a second and
  132.     give a little credit to Mr. Christensen ( the Don Garlits of CP/M )
  133.     for the fine FREE utilities he has given to ALL of us over the years.
  134.     The next time you do a modem transfer, you can thank him for the
  135.     original XMODEM from which all others have transpired.
  136.  
  137. Why NARC...
  138.  
  139.         It seemed like a good idea. Short for uN-ARC. The idea
  140.     was originally Bob Freed's.
  141.  
  142. Acknowledgements..
  143.  
  144.         I would like to thank Bob Freed for his allowing me to
  145.     examine his Z80 code before writing NARC. Bob wrote UNARC for the
  146.     CP/M world and is ( as of this writing 4/28/87) working on NOAH
  147.     the ARCing program for CP/M. I would also like to thank System
  148.     Enhancement Associates for releasing their source code in "C".
  149.     Without both of the above, NARC would have been a much larger chore
  150.     than it was. Note also that the crunching algorithm used in ARC.EXE
  151.     was taken from COMPRESS, used in UNIX.
  152.         A special thanks to Curt Edwards, Jerry Taylor, Frank Roemer,
  153.     Gil Levitch and Paul Bowling for their "eagle-eyes" in locating errors.
  154.  
  155. The Future...
  156.  
  157.         This is the first release of NARC and timing tests have
  158.     shown that NARC is significantly faster than ARC.EXE v5.20, but it is
  159.     also significantly slower than PKXARC. Since this is my first venture
  160.     into the world of ARC files, I don't consider this to be too bad,
  161.     but the area of speed will be the main focus for the next version.
  162.     EGA support will also be a topic of discussion.
  163.  
  164.  
  165.  
  166.                 Page 1
  167.  
  168.  
  169.  
  170.  
  171.                                ═════════════
  172.                        COMPATIBILITY
  173.                                ═════════════
  174.  
  175.  
  176.         NARC is compatible with all known "skrunching" algorithms,
  177.     that is up to and including Squashing. NARC is compatible with
  178.     ARC.EXE version 5.20 and PKxARC. NARC supports Squashing which is
  179.     nothing more than a variation of the crunching algorithm. NARC also
  180.     recognizes the .ARK extension soon to be prevalent in the CP/M world
  181.     via Bob Freed's CP/M archive facility, NOAH.
  182.  
  183.  
  184.  
  185. Author's Ramblings
  186.  
  187.  
  188.         System Enhancement Associates, I am told is dropping the
  189.     ball as far as ARC.EXE goes. I think that they deserve a great round
  190.     of applause for their contribution and help with a formidable problem,
  191.     namely, storage space (or lack thereof). Phil Katz has the ball at
  192.     this point and I hope that he uses good judgement in future releases.
  193.     Just for the record, I don't plan on writing an ARCer, there are too
  194.     many hands in the pot already.
  195.  
  196.         The oldest version of ARC.EXE that I can find is version 3.10,
  197.     released 5-1-85. This version supports storage methods up to
  198.     and including squeezing (no crunching). If anyone has an older version
  199.     I would be interested in seeing it. Here is a list of the versions
  200.     that I do have and would be interested in getting any other versions
  201.     floating around.
  202.  
  203.         3.10    4.10    4.50    4.52    5.00    5.10    5.12    5.20
  204.  
  205.  
  206.  
  207.                       ═════════════════════════════════════════
  208.               ARCHIVE STORAGE METHODS SUPPORTED BY NARC
  209.                       ═════════════════════════════════════════
  210.  
  211.  
  212.  
  213.             Packing        - all versions
  214.             Squeezing    - Huffman Coding
  215.             Crunching    - all versions (LZW encoding)
  216.             Squashing    - one version (hopefully the only one)
  217.  
  218.  
  219.     Note: LZW stands for Lempel-Ziv-Welch
  220.  
  221.  
  222.  
  223.                 Page 2
  224.  
  225.  
  226. OverView...
  227.  
  228.         When NARC is first invoked, it saves the current drive/path
  229.     for use again on exit, so you always end up where you started. Some
  230.     folks like that and some don't. I DO. NARC first searches the default
  231.     path for ARC files and if any are found they are displayed in a window
  232.     on the left side of the screen. The arrow keys (or the mouse) may
  233.     be used to move the cursor bar up and down the window, there are
  234.     three ways to select the highlighted ARC file ;
  235.  
  236.         (1) Hit the ENTER key
  237.         (2) Press the left mouse button
  238.         (3) Hit the F1 key.
  239.  
  240. NOTE: Function keys F1 and F2 mimick the mouse buttons as ;
  241.  
  242.         F1 = left mouse button
  243.         F2 = right mouse button
  244.         F3 = both mouse buttons
  245.  
  246.         NARC will determine whether a monochrome or color monitor
  247.     is being used and act accordingly. EGA is not directly supported
  248.     at this point, because I don't have one and can't test the routines.
  249.  
  250.  
  251.         After selecting the sub-file of interest, NARC displays
  252.     all of the ARC sub-files and their statistics on the screen. You
  253.     are also given a menu bar at the bottom of the screen. You may
  254.     use the arrow keys or the mouse to move the cursor bar to the
  255.     desired selection and then select with the F1 key or the ENTER key
  256.     or the left mouse button. As the cursor bar is moved, you are also
  257.     given a brief description of the highlighted command. The commands
  258.     will now be discussed individually.
  259.  
  260.  
  261.     Note: You may also select any option from the command bar by
  262.           entering the first letter of the command.
  263.  
  264.         The ESCape key will exit the program from any of the
  265.     windows or the command bar.
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.                 Page 3
  280.  
  281.                                   ════════
  282.                               COMMANDS
  283.                                   ════════
  284.  
  285.  
  286.  
  287.  
  288. ═══════════════
  289. Extract Command
  290. ═══════════════
  291.  
  292.         Selecting this option will cause another prompt to be
  293.     displayed, asking whether you wish to extract the highlighted
  294.     file or tagged files. (Files are tagged with the space bar). "Point
  295.     and shoot" here again as before. The ESC key or the right mouse
  296.     button will abort the operation.
  297.  
  298.  
  299.  
  300.     Highlighted File
  301.  
  302.         When EXTRACT is selected, you will be asked for a drive/path
  303.     to extract the file to. If you simply hit ENTER or the F1 key or the
  304.     left mouse button, the file will be extracted to the default
  305.     drive/path. You may also enter any valid DOS drive/path. The ESC key
  306.     or the F2 key or the right mouse button will abort the operation.
  307.     
  308.  
  309.     Tagged Files
  310.  
  311.         The Space bar (or F3 key) is used to TAG the current file.
  312.     When a file is tagged, an asterisk will be displayed on the line with
  313.     the current file in column 80. As a side note, the asterisk was chosen
  314.     as a reminder of the CP/M days of NSWEEP and B29. The space bar will
  315.     also unTAG a file, thus it is a "toggle". When the space bar is
  316.     pressed, an asterisk will appear as described above and    the cursor bar
  317.     will move to the next file. When the "TAGGED" option is selected from
  318.     the command line, all files that have been tagged, will be extracted
  319.     to the SAME drive/path.
  320.  
  321.         After the file is extracted, it's date and time are set to
  322.     those contained in the ARC file. The file is also checked for size
  323.     and CRC, if both of these do not match exactly what was contained in
  324.     the ARC file header, then an error has occured and the user is notified
  325.     The files will also remain tagged after the extraction.
  326.  
  327.  
  328. ════════════
  329. View Command
  330. ════════════
  331.  
  332.         This option will display the currently highlighted file
  333.     on the screen. The space bar is used to pause and the ESC key is
  334.     used to abort. No mouse support here, since it slows things down too
  335.     much.
  336.                 Page 4
  337.  
  338.  
  339. ═════════════
  340. Print Command
  341. ═════════════
  342.  
  343.         The print option will print the currently highlighted file.
  344.     After selecting the print option, you will be asked which character
  345.     pitch you want to print in. Enter the number that you wish (or 0 for
  346.     the default pitch) and the printer will be set to that pitch.
  347.  
  348.     NOTE: The printer strings that come installed with NARC are compatible
  349.           with EPSON printer strings. If you wish to install NARC with
  350.           your own strings, see NARCCFG.DOC for complete instructions.
  351.  
  352.         After you have selected the printer pitch, you will be shown
  353.     three more options. Use the arrow keys to move left and right.
  354.     The space bar (or right mouse) is used to toggle the options ON or OFF.
  355.     When you have finished and are ready to print, hit ENTER
  356.     (or left mouse button). The options are;
  357.  
  358.  
  359.         Format -     YES - This option causes NARC to format the
  360.                       output with page breaks and page numbers.
  361.                 NO  - NARC does not format the file.
  362.  
  363.     The following two options work independently of the Format option.
  364.  
  365.         Strip High -    YES - NARC will strip the high bit off each
  366.                       character before it is sent to the
  367.                       printer. Some word processors set this
  368.                       high bit on some characters as a means of
  369.                       text formatting. These characters will
  370.                       print as garbage usually.
  371.                 NO  - NARC will not strip the high bit.
  372.  
  373.         Strip Control -    YES - NARC will strip all control characters
  374.                       from the file before it is printed. This
  375.                       is useful on files that have imbedded
  376.                       formatting characters, and you wish to
  377.                       have NARC provide the formatting.
  378.                 NO  - NARC will not strip the control chars.
  379.  
  380.  
  381.  
  382. ════════════════
  383. ARC-wind Command   Note: The right mouse button will also pop this window up.
  384. ════════════════
  385.  
  386.         This option will display the window containing all of the
  387.     ARC files in the current sub-directory. Move the cursor bar up and
  388.     down with the mouse or arrow keys and select with the F1 key or
  389.     ENTER key or left mouse button.
  390.  
  391.  
  392.  
  393.                 Page 5
  394.  
  395.  
  396. ════════════════
  397. DRV-wind Command
  398. ════════════════
  399.  
  400.         This option will pop up a window that contains all of the
  401.     logical drives that DOS reports to NARC. Select as before and the
  402.     ARC-window will be popped up so that you can then choose an ARC file
  403.     to examine.
  404.  
  405.  
  406. ════════════════
  407. SUB-wind Command
  408. ════════════════
  409.  
  410.         This option will pop up a window that contains all of the
  411.     sub-directories in the current directory. Point and shoot as before.
  412.     After making your selection, the window is automatically popped up
  413.     again showing the sub-directories in the new current directory. When
  414.     you get to the directory that you want, hit the F2 key or the right
  415.     mouse button and the window will be put away and the ARC-window will
  416.     be popped up so that you can then select an ARC file.
  417.  
  418.  
  419. ════════════
  420. Quit Command
  421. ════════════
  422.  
  423.         I hope I don't need to describe this one.
  424.  
  425.     NOTE: The ESCape key will also exit NARC.
  426.  
  427.  
  428. The other options...
  429.  
  430.         The F4 and F5 key functions are displayed in the lower
  431.     right hand corner of the screen. The F4 description line will
  432.     only be displayed when you have selected an ARC file and the
  433.     sub-files are displayed on the screen. If you have poped up one
  434.     of the windows, the F4 (Print Sub-Files) will not be displayed.
  435.     The F4 key will print an image of the screen less the advertisement
  436.     and command lines. The F5 key will invoke the NARC - DOS command
  437.     processor. You may then enter any valid DOS command.When you are
  438.     finished, simply hit ENTER by itself and you will be returned to
  439.     NARC. You may also enter "COMMAND" which will invoke a second copy
  440.     of COMMAND.COM, if the file COMMAND.COM is in your search path. To
  441.     return to NARC, you would then type "EXIT". 
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.                 Page 6
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.         Operating Hints and Philosophy and Shortcuts
  461.  
  462.  
  463.  
  464.  
  465.  
  466.         When NARC is first invoked, it pops up the window showing
  467.     all of the ARC files in the current directory. The first thing that
  468.     you must always do is to select an ARC file. The reason for this is
  469.     that when I want to look inside an ARC file, I will move to that
  470.     drive/directory and then call NARC. This saves me from having to
  471.     select where I want to look and what drive and all that mess. This
  472.     way, when the program comes up, I can go right to work. If you run
  473.     NARC and then decide to change drives or directories, you MUST first
  474.     select an ARC file from the first window.
  475.  
  476.         When there are no windows popped up, the right mouse button
  477.     (or F2 key) will pop up the ARC file window, regardless of where the
  478.     command line cursor bar is. This is handy when you have a lot of ARC's
  479.     that you want to thumb through, with just the 2 mouse buttons or
  480.     F1 and F2 keys, you can look through a whole directory of ARC files
  481.     in nothing flat ! Also along these lines, when the ARC window is
  482.     on the screen, the right mouse button or the ESCape key will exit the
  483.     program.
  484.  
  485.         The control system is a little tricky to at first, but I
  486.     think you will like it once you get used to it.
  487.  
  488.  
  489.  
  490.         NARC buffers 64k of the input file at one time, thus speeding
  491.     up file operations. The output buffer is 32k and should be larger in
  492.     the next version. NARC requires about 170K of RAM to operate.
  493.  
  494.  
  495.            (This prime advertising space for rent)
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.                 Page 7
  506.  
  507.                            ══════════════════════
  508.                                Error Messages.
  509.                            ══════════════════════
  510.  
  511.  
  512. Memory Allocation Error.
  513.     - NARC allocates memory when it is invoked, this says that DOS told
  514.       NARC that there was not enough memory left to run the program
  515.  
  516. ERROR: Extraction Failed due to CRC error, Hit ENTER
  517.     - After a file is extracted, the CRC contained in the ARC header is
  518.       compared to the CRC that NARC calculates, this message says that
  519.       the two were different. This is the CRC-16 polynomial.
  520.  
  521. ERROR: Extraction Failed due to FileSize error
  522.     - Same as above, except with filesize
  523.  
  524. ERROR: Disk File Inconsistency.  Hit ENTER
  525.     - This will usually mean that the user has swapped disks just after
  526.       telling NARC to View,Print or Extract and NARC does not recognize
  527.       the file.
  528.  
  529. ERROR: Incompatible Crunch Format
  530.     - Says that either the stowage code for this file is not supported by
  531.       NARC -OR- there is an error in the ARC header
  532.  
  533. ERROR: Extraction Failed due to Lack of Disk Space
  534.     - Self explanatory
  535.  
  536. Squeezed File Has a Diseased Decode Tree.
  537.     - When unsqueezing a file, NARC has found a bad entry in the decode
  538.       table.
  539.  
  540. ERROR: No directory space on destination!
  541.     - Self explanatory
  542.  
  543. Bad Path Name Dude, Hit ENTER
  544.     - The destination path that the user entered for extraction is not
  545.       a valid DOS pathname, reenter.
  546.  
  547. Requires DOS version 2.0 or above.
  548.     - NARC requires DOS 2.0 or above to operate.
  549.  
  550. Invalid archive file format
  551.     - NARC could not find any ARC headers, this is probably not an ARC file
  552.  
  553. Warning: Bad archive file header, bytes  skipped = xxxxx
  554.     - If an entry has a bad header, NARC will examine the next 64k bytes
  555.       looking for a good header. This is to maintain compatibility with
  556.       ARC v.5.20 which allows self-unpacking ARC files.
  557.  
  558. Unexpected end of  ARChive file
  559.     - Says that NARC couldn't find the last ARC header
  560.  
  561. No matching file(s) in ARChive
  562.     - ARC file is empty
  563.  
  564.                 Page 8
  565.  
  566.  
  567.                 ════════════════════════════════════════════
  568.         ARCHIVE FILE FORMATS AND GENERAL INFORMATION
  569.                 ════════════════════════════════════════════
  570.  
  571.  
  572. For Those With a Little More Curiosity...
  573.  
  574.  
  575.  
  576. The following are the currently supported stowage methods.
  577.  
  578.     1    unpacked (obsolete)
  579.     2    unpacked
  580.     3    packed
  581.     4    squeezed (after packing)
  582.     5    crunched (obsolete)
  583.     6    crunched (after packing) (obsolete)
  584.     7    crunched (after packing, using faster hash algorithm)
  585.     8    crunched (after packing, using dynamic LZW variations)
  586.     9    Squashed c/o Phil Katz (no packing) (variation on crunching)
  587.  
  588. NOTE:        LZW is Lempel-Ziv-Welch crunching algorithm
  589.  
  590.  
  591.  
  592. A little about the stowage methods.
  593.  
  594.     Packing -
  595.  
  596.         This is the simplest of the storage methods. Suppose that
  597.     you have a line of text and at the end of the line, you have 40
  598.     spaces. These 40 spaces are compressed into 3 bytes in the ARC file.
  599.     The first byte is the actual character to be expanded (in our case
  600.     a space). The second byte is a special "flag" byte that indicates
  601.     that we need to    expand these bytes. The third byte is the count byte
  602.     (in our case it would be 40). So you can see that any time the ARC'er
  603.     finds repeated bytes like this, it can compress them into 3 bytes.
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.                 Page 9
  622.  
  623.  
  624.                            ══════════════════════════
  625.                            HUFFMAN CODING (SQUEEZING)
  626.                            ══════════════════════════
  627.  
  628.  
  629.  
  630.         It does, at first, seem that making a file smaller would
  631.     be an impossible task. I will make an attempt here to shed a little
  632.     light on this subject since that is a question that I hear pretty
  633.     frequently and it is not a two minute discussion question. It does
  634.     require some thought.
  635.  
  636.         To compress a file with the Huffman algorithm, commonly called
  637.     squeezing, the first thing that must be done is to read the file
  638.     completely and count the occurences of each character. That is you
  639.     count the "A" 's and the "B" 's and so forth. There are 256 characters
  640.     in the extended ASCII character set, of which approximately 90 are
  641.     "printable", that is you can see them on the screen. The IBM set has
  642.     more "printables", but that is of no consequence, since the squeezer
  643.     deals only with the numbers and doesn't care whether or not the file is
  644.     an ASCII text file or an EXE file. Once the squeezer has counted the
  645.     occurences of each character, thus the frequency of occurence, it 
  646.     scans the table for the characters that appear the least number of
  647.     times and forms an imaginary link between them, called a node.
  648.     Somewhere else in the tree, we will later develop a pointer that
  649.     points to this node. When you start putting all of these things
  650.     together, you will form a binary tree in memory. Confused enough ?
  651.     Let us try an example.
  652.  
  653.         We have a file that is 100 bytes long and has 6 different
  654.     characters in it. We have counted the occurence of each of the
  655.     characters and found the following.
  656.  
  657.  
  658.         quantity    character
  659.  
  660.              5 -    D
  661.             10 -    A
  662.             10 -    F
  663.             20 -    B
  664.             25 -    E
  665.             30 -    C
  666.  
  667.         The spelling in the file wasn't very good, but we don't care.
  668.     Now we take these numbers and will call them the frequency of each
  669.     character. We then arrange the table as below. This is an arbitrary
  670.     arrangement, but it is useful here so as to make our tree readable
  671.     on the screen. The arrangement makes no difference.
  672.  
  673.  
  674.     Frequency    20      10      5       10      30      25
  675.  
  676.     Character    B    A    D    F    C    E
  677.  
  678.  
  679.                 Page 10
  680.  
  681.  
  682.  
  683.  
  684.         We then examine the table to find the two characters with
  685.     the smallest frequency of occurence. In our  case, it is obvious that
  686.     one of them is 5,but which 10 do we choose. As it turns out, it doesn't
  687.     matter which one you choose, we will arbitrarily choose the F. We draw
  688.     lines from the D and the F to form our node (the box below).
  689.  
  690.  
  691.     Frequency    30      10     5        10      20      25
  692.  
  693.     Character    C    A      D         F       B       E
  694.                     \    /        
  695.                      \     /
  696.                       ┌──┐
  697.                       │15│ = 5 + 10
  698.                                           └──┘
  699.  
  700.  
  701.         The number in the box is the sum of the frequencies of the
  702.     D and F characters. Now we again look for the lowest two frequencies,
  703.     except this time we do not consider the D and F characters individually,
  704.     we instead consider the node. The lowest two now are the A and the node,
  705.     that is    10 and 15. We again do some artwork.
  706.  
  707.  
  708. Frequency             30      10         5        10      20      25
  709.  
  710. Character              C      A          D         F       B      E
  711.                    \          \       /        
  712.                     \          \     /
  713.                  \        ┌──┐
  714.                   \        │15│ = 5 + 10
  715.                                    \        └──┘
  716.                                     \      /
  717.                                      \    / 
  718.                                       ┌──┐
  719.                                       │25│ = 10 + 15
  720.                                       └──┘
  721.  
  722.  
  723.         We look at the table again for the next two lowest frequencies
  724.     and now find B and E . We continue in this fashion until
  725.     the entire "tree" is built, that is until it all condenses to one node.
  726.     The leaves are the actual characters at the top of the tree and the
  727.     nodes represent branch joints with the root is at the bottom.
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.                 Page 11
  737.  
  738.  
  739. Frequency          30        10        5        10    20        25
  740.  
  741. Character        C         A        D         F     B        E
  742.              \         \    \    /       \      /
  743.               \         \     \     /         \    /
  744.                \     \      ┌──┐            ┌──┐
  745.             \      \      │15│            │45│
  746.                          \         \      └──┘            └──┘
  747.                           \         \      /              /
  748.                            \         \    /              /
  749.                             \         ┌──┐              /
  750.                              \        │25│             /
  751.                               \       └──┘            /
  752.                                \       /             /
  753.                                 \     /             /
  754.                                  ┌──┐              /
  755.                                  │55│             /
  756.                                  └──┘            /
  757.                                    \            /
  758.                                     \          /
  759.                                        ┌────┐
  760.                                        │ROOT│
  761.                                        └────┘
  762.  
  763.  
  764.         Now that our tree is made up, we can encode the file. We start
  765.     at the root (always). To encode the first character (leaf) of the tree
  766.     (the letter C), we trace up the tree until we hit the letter C at the
  767.     top. Along our journey, if we make a left turn, we record a 0 bit,
  768.     and a 1 for a right turn. So for the C, we would go left to 55 
  769.     (and record a 0) and then left again to the letter C (and record
  770.     another 0), so the Huffman code for our letter C is 00. For A we
  771.     go left to 55, right to 25 and left to A and it becomes 010. By doing
  772.     all of the letters this way, we find the following.
  773.  
  774.  
  775.             C = 00        ( 2 bits )
  776.             A = 010        ( 3 bits )
  777.             D = 0110    ( 4 bits )
  778.             F = 0111    ( 4 bits )
  779.             B = 10        ( 2 bits )
  780.             E = 11        ( 2 bits )
  781.  
  782.         Mind that the zeroes and ones above are bits and not bytes.
  783.     Each character was represented in the original file by 8 bits (one byte)
  784.     and since we have reduced the number of bits needed to represent each
  785.     character, we therefore reduce the size of the file. The savings add up
  786.     as follows,
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.                 Page 12
  794.  
  795.  
  796.    character     frequency      original bits    squeezed bits   savings
  797.  
  798.        C            30           30 x 8 = 240      30 x 2 = 60    180
  799.        A            10           10 x 8 = 80       10 x 3 = 30     50
  800.        D             5            5 x 8 = 40        5 x 4 = 20     20
  801.        F            10           10 x 8 = 80       10 x 4 = 40     40
  802.        B            20           20 x 8 = 160      20 x 2 = 40    120
  803.        E            25           25 x 8 = 200      25 x 2 = 50    150
  804.                ══════════               ══════            ═════  ═════
  805. Totals             100                    800              240    560
  806.                                            │                │
  807.                   original file size ──────┘                │
  808.                   squeezed file size ───────────────────────┘
  809.  
  810.  
  811.         240 is 30% of 800, so we have compressed this file by 70%.
  812.     Golly Wally, that seems pretty good. The rub lies in the fact that in
  813.     order to reconstruct the original file, we must have access to the
  814.     decode tree and since each tree will be different for each file, we
  815.     must therefore save the tree with the file. It turns out that the tree
  816.     can have only 255 nodes in a bytewise compression technique and each
  817.     node will hold 4 bytes as pointers, a full table will be about 1k long.
  818.     The table in our example has 5 nodes plus the 6 leaf nodes (where our
  819.     characters are), totalling 11. 4 times 11 is 44 and if we add a few
  820.     bytes for storing the node count and some other statistics, our table
  821.     is about 50 bytes long.    If we look at the 240 in the above table this
  822.     gives the total number of bits that it will take to encode the file,
  823.     divide 240 by 8 to get the number of bytes (30) and add this to our 50,
  824.     we get a compressed file size of 80 bytes. Since our original file was
  825.     100 bytes, we have achieved a 20% reduction in file size. Not bad.
  826.     What we have really accomplished is a translation of character sets,
  827.     with our new set requiring less space than the original ASCII set.
  828.  
  829.     How far can we go ?
  830.  
  831.         If we look at the maximums that we can obtain for the different
  832.     bit combinations in a optimally skewed tree, that is a tree that is not
  833.     exactly symetrical, we find that we can have only 4 - 2 bit codes,
  834.     8 - 3 bit codes, 16 - 4 bit codes, 32 - 5 bit codes, 64 - 6 bit codes,
  835.     128 - 7 bit codes, the remaining 4 will be 8 bit codes.
  836.  
  837.  
  838.                 2    - 1 bit codes
  839.                 4    - 2 bit codes
  840.                 8    - 3 bit codes
  841.                 16    - 4 bit codes
  842.                 32    - 5 bit codes
  843.                 64    - 6 bit codes
  844.                 128    - 7 bit codes
  845.                  --------
  846.                     254
  847.  
  848.  
  849.  
  850.                 Page 13
  851.  
  852.         And since we have a total of 256 different bytes to encode,
  853.     the remaining 2 characters must have 8 bit codes. If we add the number
  854.     of bits that this represents, we find a total of 1554 bits or
  855.     195 bytes. So at maximum, we have compressed the 256 bytes to 195 or
  856.     33%, thus the idealistic maximum that can be achieved with the Huffman
  857.     algorithm is 33% when using a byte level implementation.
  858.  
  859.         One final note; The Huffman scheme requires the input file
  860.     to be read twice, once to count characters and frequencies and then
  861.     again to do the actual encoding. The major differences in Huffman
  862.     coding and crunching lie in the fact that crunching is a one pass
  863.     operation and does not require the table to be stored with the file.
  864.     Also Huffman coding is extremely vulnerable to errors, for example,
  865.     imagine what would happen if you skipped one bit when squeezing the
  866.     file, all of the remaining characters in the file would become
  867.     the proverbial garbage, since we are looking at the file on a bit
  868.     level.
  869.  
  870.         NARC uses the method described in K. & R. ppg. 130 for
  871.     setting up the binary tree with several modifications. The simple
  872.     binary tree is acceptable for this, since the tree never grows and
  873.     therefore will never become unbalanced.
  874.  
  875.         If you followed that, now go back and read the second
  876.     paragraph again, maybe it will make sense this time.
  877.  
  878.  
  879.                            ══════════════════════
  880.                                  CRUNCHING
  881.                            ══════════════════════
  882.  
  883.  
  884.         Crunching began with an article by J. Ziv and A. Lempel
  885.     in IEEE Trans. Information Theory, May 1977, where the method was
  886.     originally described. Terry A. Welch wrote a definitive application
  887.     article in  IEEE Computer June 1984 which described in detail how
  888.     to apply the algorithm and some common problems encountered. Thus
  889.     the name LZW compression.
  890.  
  891.         Crunching takes the Huffman coding method a step further
  892.     as it does not include a table with the crunched file. The crunching
  893.     algorithm also "learns" as it proceeds through the file. If it finds
  894.     repeated strings in the file, they will be encoded into    a table. This
  895.     table is set up (in NARC's implementation) as a 4096 by 3 table.
  896.     Each entry is formatted as <PREF>,<SUFFIX>, where PREF is a 2 byte
  897.     pointer to another entry. SUFFIX is the last byte of the string.
  898.     Representing the PREF's as pointers rather than values speeds up
  899.     most operations in NARC. This idea came from Bob Freed.
  900.  
  901.         One obvious benefit of crunched files is the fact that there
  902.     is no need to include the encoding table in the compressed file as was
  903.     the case with squeezing. Another great benefit is the fact that
  904.     crunching is a one pass operation as opposed to the two pass situation
  905.     in squeezed files.
  906.  
  907.                 Page 14
  908.  
  909.  
  910.         Crunching begins by creating an "atomic" table, that is a
  911.     table in RAM that contains 256 entries, one for each character in the
  912.     extended ASCII set. The values range sequentially from 0 to 255. The
  913.     table entries are arranged as follows.
  914.  
  915.         Prefix Pointer (2 bytes) and Suffix byte (1 byte)
  916.  
  917.     In this inital table setup, the Suffix bytes are the 0 through 255
  918.     mentioned above. These are the "atomic" characters, in that they
  919.     must be in the table before curnching can begin, since all files
  920.     contain some portion of this character set. We do not know which
  921.     characters will be included in any given file and which ones will be
  922.     excluded, so we must include them all in our initial table. Once this
  923.     table is set up, we can begin crunching.
  924.  
  925.         The Prefix pointer will contain a value that is a pointer
  926.     to another string. When the table is initially set up, there are no
  927.     other strings, so this Prefix pointer is set to a special "Null"
  928.     string, that is it points nowhere. We must be careful when crunching
  929.     the file, to look for this special pointer and act accordingly when
  930.     we encounter it.
  931.  
  932.         This Prefix and Suffix business is used to "build" long
  933.     strings. If we read the input file and found that the first character
  934.     was the letter "I", we would look this letter up in the string table
  935.     by hashing (computing an address). If we found the letter in the table
  936.     (which we certainly will on the first character), then we ouput it's
  937.     "hashed" address as a code to the output file (the crunched file).
  938.     Suppose then, that the next character input from the file was the
  939.     letter "D", the  cruncher would then look at the I and the D together
  940.     to see if they exist as a string in the table. Well of course, since
  941.     this is the second character of the file, we know that it doesn't,
  942.     so the cruncher forms a new entry in the string table. This entry
  943.     has as its' Prefix pointer, a value that "points" to the letter "I"
  944.     entry in the table, that we made a minute ago. The suffix byte in this
  945.     case would be the letter "D". Now another code is output to the
  946.     crunched file, representing the letter "D". Well this is great,
  947.     we have now turned 2 bytes from the input file (16 bits) into 3 bytes
  948.     in the output file (24 bits). You are correct, crunching begins by
  949.     "not crunching", but it is a crazy world ! The real value becomes
  950.     apparent when we run into this same sequence "ID" in the input file
  951.     again. Now we will find an entry for it in the string table and we
  952.     can output a single 12 bit code that stands for "ID", thus saving
  953.     4 bits. The cruncher continues "learning" strings like this until
  954.     the file is crunched. It should be noted that the string table is
  955.     dynamnically changing as the input file is processed.
  956.  
  957.  
  958.  
  959.         NARC supports all of the current "skrunching" algorithms. 
  960.     A brief description of each follows.
  961.  
  962.  
  963.  
  964.                 Page 15
  965.  
  966.  
  967.  
  968.  
  969.  
  970. Version    1    - "STORED" File is simply stored (obsolete now, 25 byte header)
  971.  
  972.         NOTE: Files stored with this version are rare.
  973.  
  974. Version    2    - "STORED" Current version of simple storage
  975.         This version was implemented with the implementation of
  976.         file compression. The main difference in version 1 and 2
  977.         is the ARC header (see header section below), version 1
  978.         has a header length 4 bytes smaller than any of the rest
  979.         of the storage methods since in version 1 there was no
  980.         need to store the original file length separately from the
  981.         stored file length since they were the same.
  982.  
  983.  
  984. Version 3    - "PACKED" Repeated bytes are packed into a three byte string
  985.         (see Packing above)
  986.  
  987.  
  988. Version    4    - "SQUEEZED" after packing
  989.         The file is first packed as described above and then squeezed
  990.  
  991.  
  992. Version    5    - "CRUNCHED" This is the first implementation of LZW released
  993.         Uses fixed length codes and a complex hashing function.
  994.         (obsolete now) (See hashing below)
  995.  
  996.         NOTE: Files compressed with this version are hard to find.
  997.               Version was released only one month when next version
  998.               came out.
  999.  
  1000.  
  1001. Version    6    - "CRUNCHED" after packing
  1002.         The file is first packed and then crunched. Uses fixed length
  1003.         codes and the same hashing function as version 5.
  1004.  
  1005.  
  1006. Version    7    - "CRUNCHED" after packing
  1007.         Same as version 6 except a faster hashing function is used.
  1008.  
  1009.         NOTE: Thom Henderson (author of ARC) has this to say about
  1010.               version 7. "This approach was abandoned because dynamic
  1011.               Lempel-Ziv works as well, and packs smaller also. However
  1012.               inadvertent release of a developmental copy forces us to
  1013.               leave this in."
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.                 Page 16
  1021.  
  1022.  
  1023. Version    8    - "CRUNCHED" after packing
  1024.         Uses variable length codes in the crunched file (9 to 12 bits)
  1025.         and has a faster hash function (actually not hashing at all,
  1026.         but for the sake of consistency, we will call it that)
  1027.         This version also resets the string table when it becomes full
  1028.         which benefits the compression ratio of larger files. This
  1029.         resetting is commonly called an adaptive reset.
  1030.  
  1031.  
  1032. Version    9    - "SQUASHING" (variation on crunching scheme)
  1033.         This version uses the same hashing function as version 8
  1034.         but varies the crunching codes from 9 to 13 bits. There is
  1035.         also no packing, which affords the string table the opportunity
  1036.         to "learn" longer codes and thus improve the compression
  1037.         ratio (benefits "real large" files).
  1038.  
  1039.  
  1040.  
  1041. ARC file header structure is same for both DOS and CP/M
  1042.  
  1043. Byte number        Value(s)    Meaning
  1044. ─────────────────────────────────────────────────────────────────────────────
  1045.     1        1Ah        Header Flag
  1046.     2        0-9        Compression Version
  1047.     3-15        ---        ASCIIZ compressed filename
  1048.     16-19        ---        Compressed file size in bytes
  1049.                     Low Word, High Word with each word
  1050.                     in LoHi format
  1051.     20-21        bits        DOS date format
  1052.             15-9        Year
  1053.              8-5        Month
  1054.              4-0        Day        (all zeroes means no date)
  1055.     22-23        bits        DOS time format
  1056.             15-11        Hours (military)
  1057.             10-5        Minutes
  1058.              4-0        Seconds
  1059.     24-25        ---        CRC-16 in LoHi format of uncompressed
  1060.                     file. ------- This is important.
  1061.     26-29        ---        Original uncompressed  file size
  1062.                 NOTE:    Version 1 files are not compressed
  1063.                     so the length can be  found with
  1064.                     bytes 16-19, also the header len
  1065.                     for version 1 files is 25 bytes.
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.                 Page 17
  1077.  
  1078.  
  1079.  
  1080. Hashing.....
  1081.  
  1082.         Hashing is simply an arithmetic way of coming up with
  1083.     an address in a table. You have a set of input numbers (codes)
  1084.     that will map one-to-one with the output codes in an ideal situation.
  1085.     That is, each time you input a certain number, you can rest assured
  1086.     that the output will always return the same output number. This
  1087.     is not quite the case in the current versions of .ARC files. The
  1088.     reason is that the algorithm would require a MEG or so of RAM for
  1089.     implementation. The utilization of a smaller string table in all of
  1090.     the ARC programs introduces the possibility of producing the same
  1091.     output number for 2 or more input numbers. This is called a hash
  1092.     collision. This is handled separately in .ARC files with what is
  1093.     called a "collision table", which helps to locate the correct table
  1094.     entry.
  1095.  
  1096.  
  1097.         There are three versions of "hashing" used in ARC files.
  1098.  
  1099. Hash1    - Key = upper 12 bits of lower 18 bits of unsigned square of
  1100.         (prefix code + suffix byte) OR 800h
  1101.  
  1102.         Used in stowage versions 5 and 6
  1103.  
  1104. Hash2    - Key = lower 12 bits of usigned product of
  1105.         (prefix code + suffix byte) * 15073
  1106.  
  1107.         Used in stowage version 7
  1108.  
  1109. Hash3    - Key = next available address in table.
  1110.  
  1111.         Used in stowage versions 8 and 9
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.     CRC calculations -
  1118.  
  1119.         NARC does not use the traditional table lookup method for
  1120.     calculating the CRC of the file. The table approach requires the table
  1121.     to be in RAM and takes up more space. NARC calculates the CRC on the
  1122.     fly, which requires no table and saves space. The algorithm is taken
  1123.     from the definitive article by Aram Perez in IEEE Micro, June '83.
  1124.      The polynomial is X^16 + X^15 + X^2 + X^1 which is not compatible with
  1125.     the Xmodem CRC.
  1126.  
  1127.  
  1128.     Gary Conway
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.                 Page 18
  1136.  
  1137.  
  1138.                        ══════════════════════════════
  1139.                        ARC RELEASE DATES AND VERSIONS
  1140.                        ══════════════════════════════
  1141.  
  1142.  
  1143.  
  1144.       These are the various versions of ARC.EXE that I have and what
  1145.     versions of storage they supported. PKxARC supports all of these
  1146.     methods as well since they were all originally created by ARC.EXE.
  1147.  
  1148.  
  1149.     Date                              Stowage Methods
  1150.     Released    Version              Supported
  1151.  
  1152.     05-01-85    3.10        Storing,Packing,Squeezing  (1-4)
  1153.                       ( version 5 in here somewhere)
  1154.     06-26-85    4.10        Up to version 6 of crunching
  1155.     11-18-85    4.50        Up to version 6 of crunching
  1156.     12-04-85    4.52        Up to version 6 of crunching
  1157.                       ( version 7 in here somewhere)
  1158.     01-21-86    5.00        Up to version 8 of crunching
  1159.     01-31-86    5.10        Up to version 8 of crunching
  1160.     02-05-86    5.12        Up to version 8 of crunching
  1161.     10-24-86    5.20        Up to version 8 of crunching
  1162.  
  1163.  
  1164.         This list is compiled in an attempt to start some kind
  1165.     of historical record as to what transpired in the ARC world. I would
  1166.     be interested in hearing of addtions.
  1167.  
  1168.  
  1169.             ═════════════════════════
  1170.             NARC.EXE REVISION HISTORY
  1171.             ═════════════════════════
  1172.  
  1173. Version 1.0    - First Release 6.10.87
  1174.  
  1175. Version 1.1
  1176.     - Fixed bug in tagged extraction to other than default path
  1177.     - Deletes partial file when extraction fails due to lack of disk space
  1178.     - Fixed bug dealing with improper end of file condition in HEX view
  1179.     - Stronger ARChive header checking. Handles special case where two
  1180.       1Ah bytes are encountered after a bad header
  1181.     - Fixed bug with PK zero length files
  1182.     - Introduction of NARCCFG.EXE, replacing NARCLOAD.EXE and NARC.CFG
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189. End of NARC.DOC            Copyright (c) 1987    Infinity Design Concepts
  1190.  
  1191.  
  1192.                 Page 19
  1193.  
  1194.